package com.xizi.lotterySystem.service.activitystatus.operator;

import com.xizi.lotterySystem.dao.mapper.ActivityUserMapper;
import com.xizi.lotterySystem.service.dto.ConvertActivityStatusDTO;
import com.xizi.lotterySystem.service.enumerate.ActivityUserStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UserOperator extends AbstractActivityOperator {
    private static final Logger log = LoggerFactory.getLogger(UserOperator.class);
    @Autowired
    private ActivityUserMapper activityUserMapper;

    @Override
    public int sequence() {
        return 1;
    }

    @Override
    public Boolean needConvert(ConvertActivityStatusDTO param) {
        // 校验参数
        if (!param.getTargetActivityUserStatusEnum().name().equalsIgnoreCase(ActivityUserStatusEnum.COMPLETED.name())){
            return false;
        }
        return true;
    }

    @Override
    public Boolean convert(ConvertActivityStatusDTO param) {
        Long activityId = param.getActivityId();
        List<Long> userIds = param.getUserIds();

        Long row = activityUserMapper.batchUpdateStatus(userIds,activityId,param.getTargetActivityUserStatusEnum());
        return row != null && row == param.getUserIds().size();
    }
}
